package com.smartstate.admin.biz.entity.vo;

import com.smartstate.admin.biz.entity.bo.Permission;
import com.smartstate.common.base.vo.BaseVO;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springframework.beans.BeanUtils;
import org.springframework.util.CollectionUtils;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
@Data
public class PermissionVo extends BaseVO implements Serializable {

    @ApiModelProperty(value = "权限名称")
    private String name;

    @ApiModelProperty(value = "权限编码")
    private String code;

    @ApiModelProperty(value = "路径")
    private String urlPath;

    @ApiModelProperty(value = "父级权限")
    private String pid;

    @ApiModelProperty(value = "菜单类型")
    private Integer type;

    @ApiModelProperty(value = "图标")
    private String icon;

    @ApiModelProperty(value = "排序")
    private Integer sort;

    @ApiModelProperty(value = "父权限名称")
    private String pidName;

    @ApiModelProperty(value = "组件")
    private String component;

    @ApiModelProperty(value = "拥有权限",hidden = true)
    private Integer roleType;

    @ApiModelProperty(value = "pc和app(0:pc,1:app)")
    private Integer isWeb;

    public PermissionVo buildVo(Permission permission){
        BeanUtils.copyProperties(permission,this);
        return this;
    }

    public List<PermissionVo> buildVoList(List<Permission> list){
        List<PermissionVo> voList = new ArrayList<>();
        if(CollectionUtils.isEmpty(list)){
            return voList;
        }
        list.forEach(item ->{
            PermissionVo vo = new PermissionVo();
            BeanUtils.copyProperties(item,vo);
            voList.add(vo);
        });
        return voList;
    }
}
